{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "买入费用: 31.36 元\n",
      "赎回费用: 45.36 元\n",
      "一次买卖的总费用: 76.72 元\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "# 佣金费用\n",
    "commission_rate_var = 0.00012\n",
    "# 过户费用\n",
    "transfer_fee_per_share_var = 0.001\n",
    "# 印花费用\n",
    "stamp_duty_rate_var = 0.0005\n",
    "# 最低费用\n",
    "min_fee = 5\n",
    "\n",
    "def calculate_buying_fee(total_amount, commission_rate=commission_rate_var, transfer_fee_per_share=transfer_fee_per_share_var):\n",
    "    \"\"\"计算买入费用\"\"\"\n",
    "    commission = total_amount * commission_rate\n",
    "    transfer_fee = transfer_fee_per_share * total_amount\n",
    "    total_fee = commission + transfer_fee\n",
    "    total_fee = max(total_fee, min_fee)  # 如果费用低于最低费用，则按最低费用计算\n",
    "    return total_fee\n",
    "\n",
    "def calculate_redemption_fee(total_amount, commission_rate=commission_rate_var, transfer_fee_per_share=transfer_fee_per_share_var, stamp_duty_rate=stamp_duty_rate_var):\n",
    "    \"\"\"计算赎回费用\"\"\"\n",
    "    commission = total_amount * commission_rate\n",
    "    transfer_fee = transfer_fee_per_share * total_amount\n",
    "    stamp_duty = total_amount * stamp_duty_rate\n",
    "    total_fee = commission + transfer_fee + stamp_duty\n",
    "    total_fee = max(total_fee, min_fee)  # 如果费用低于最低费用，则按最低费用计算\n",
    "    return total_fee\n",
    "\n",
    "def calculate_total_fees(amount):\n",
    "    \"\"\"计算一次买卖的总费用（包括买入和卖出费用）\"\"\"\n",
    "    buy_fee = calculate_buying_fee(amount)\n",
    "    sell_fee = calculate_redemption_fee(amount)\n",
    "    total_fee = buy_fee + sell_fee\n",
    "    return buy_fee, sell_fee, total_fee\n",
    "\n",
    "# 示例：计算 50000 元的买入和赎回费用\n",
    "amount = 28000  # 输入金额\n",
    "buy_fee, sell_fee, total_fee = calculate_total_fees(amount)\n",
    "\n",
    "print(f\"买入费用: {buy_fee:.2f} 元\")\n",
    "print(f\"赎回费用: {sell_fee:.2f} 元\")\n",
    "print(f\"一次买卖的总费用: {total_fee:.2f} 元\")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
